New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update disabling-http-keep-alive.md for server-side only #43374
Conversation
Fixes vercel#43354 It is not possible to specify an `agent` on a single `fetch()` call since the types for `fetch` come from TypeScript where `agent` is not supported as an option.
e078ebe
to
6b863fe
Compare
You said it’s not possible with TS types but what about with JS? Are the types wrong? I also think the behavior is different for Node.js 16 vs 18 because it’s no longer poly filled on 18, it’s native. |
The TypeScript However because Next.js supports also using With Next.js 13 running on Node 18, you're right However running on Node <18 Next.js polyfills So I guess this is a super complex scenario where the type is not sophisticated enough to know if you're running I think the TypeScript type definition of |
``` | ||
|
||
To override all `fetch()` calls globally, you can use `next.config.js`: | ||
To disable HTTP Keep-Alive for all `fetch()` calls on the server-side, open `next.config.js` and add the `httpAgentOptions` config: | ||
|
||
```js | ||
module.exports = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this uses the same Agent behavior so it probably wont work either on Node.js 18
cc @Ethan-Arrowood who implemented undici and might know more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on our testing, unfortunately these agent options aren't compatible with undici and there's no equivalent alternative.
We had to intentionally disable Node 18's undici with --no-experimental-fetch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undici's fetch accepts dispatcher which fulfills a similar role as agent
though it requires undici specific Pool/Agent/etc instead of node's http agent.
Co-authored-by: Steven <steven@ceriously.com>
For anyone else that encounters this -- I mistook this as suggesting new behavior in Next 13, when I believe actually any previous version of Next running on Node18 will use undici and not the fetch polyfill: https://github.com/vercel/next.js/blob/canary/packages/next/src/server/node-polyfill-fetch.ts#L4 |
fixes #43354
It is not possible to specify an
agent
on a singlefetch()
call since the types forfetch
come from TypeScript whereagent
is not supported as an option.